# display_handler.py
import cv2
import time
import camera_handler
from flask1.app import Web

web = Web()
class DisplayHandler:
    @staticmethod
    def show_with_model(predictor, frame, start_time, j, label_time):
        # 省略部分代码(已补充)


        res, img = predictor.Predict(frame)

        #img是图片，reslabel标签，centerxy是xy坐标，object为0不清除为1执行清除，num_detected_objects是每次有几个物体在检测
        img, reslabel, center_x, center_y, object, num_detected_objects = predictor.draw(img, res, start_time, j, label_time)

        # 省略部分代码
        print(label_time)
        print("同种类类型有" + str(num_detected_objects))

        if object:
            print("开始强制清除")
            #plat.TurnToGarbage("Other")

        # print(center_x,center_y)
        cv2.imshow("frame", img)
        # =======================
        #garbageType = dh.dataHandle(reslabel)
        # print(reslabel)
        #print(reslabel, garbageType)
        #plat.TurnToGarbage(garbageType)
        #if garbageType == 'Recyclable':
            #plat.Compress()
            #time.sleep(5)
            #plat.Uncompress()

        try:
            if not reslabel == "None":
                web.NewData(reslabel,num_detected_objects)
                #dat = fd.GetFullStatus()
                #print(dat)
                #web.UpateFullStatus(dat)
                time.sleep(1)
        except KeyboardInterrupt:
            web.Close()
        # print(res)
        # image = p.draw(frame, res)
        # cv2.imwrite(r'./test.jpg', image)
        cv2.waitKey(1)
        # time.sleep(1)

